package com.baizhi.service.impl;

import com.baizhi.dao.AdminDao;
import com.baizhi.entity.Admin;
import com.baizhi.service.AdminService;
import com.baizhi.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

public class AdminServiceImpl implements AdminService {
    @Override
    public Boolean login(String username, String password) {
        Boolean flag=false;
        SqlSession sqlSession = MyBatisUtils.openSession();
        try{
            AdminDao adminDao = sqlSession.getMapper(AdminDao.class);
            Admin admin = adminDao.selectAdminByUsername(username);
            if(admin==null){
                flag=false;
            }
            if(admin.getPassword().equals(password)){
                flag=true;
            }
            sqlSession.commit();
        }catch (Exception e){
            e.printStackTrace();
            sqlSession.rollback();
            throw new RuntimeException(e);
        }finally {
            MyBatisUtils.close(sqlSession);
        }
        return flag;
    }
}
